import Vue from 'vue'
import Router from 'vue-router'
import Login from './components/login.vue'
import Home from './components/home.vue'

Vue.use(Router)

const router=new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {path: '/',redirect:'/login'},
    {path:'/login',component:Login},
    {path:'/home',component:Home}
  ]
})
router.beforeEach((to, from, next) => {
  if(to.path=='/login')return next()
  const token=sessionStorage.getItem('token')
  if(!token)return next('/login')
  next()
})
export default router
